﻿@model Account

<div class="container mt-2">
    <div class="row justify-content-center">
        <div class="col-9">
            <h2>Edit Account</h2>
            @if (TempData["error"] != null)
            {
                <div class="alert alert-danger mt-3">@TempData["error"]</div>
            }
            <form method="post" asp-action="UpdateAccount">
                <input type="hidden" name="AccountID" value="@Model.AccountID" />

                <div class="form-group">
                    <label for="syncType">Sync Type:</label>
                    <div>
                        <input type="radio" name="syncType" value="manual" @(Model.syncType == "manual" ? "checked" : "")> Manual Sync
                        <input type="radio" name="syncType" value="automatic" @(Model.syncType == "automatic" ? "checked" : "")> Automatic Sync
                    </div>
                </div>
                <div class="form-group">
                    <label for="accountType">Select Account Type:</label>
                    <select class="form-control" name="AccountType" required>
                        <option value="@Model.AccountType">@Model.AccountType</option>
                        <option value="BankAccount">Bank Account</option>
                        <option value="CreditCard">Credit Card</option>
                        <option value="Investment">Investment Account</option>
                    </select>
                    <span asp-validation-for="AccountType" class="text-danger"></span>
                </div>
                <div class="form-group">
                    <label for="accountNumber">Account Number:</label>
                    <input class="form-control" type="text" name="AccountNumber"
                           value="@Model.AccountNumber" required>
                    <span asp-validation-for="AccountNumber" class="text-danger"></span>
                </div>

                <div id="institutionNameField" class="form-group" style="display: none;">
                    <label for="institutionName">Enter Institution Name:</label>
                    <input class="form-control" type="text"
                           name="InstitutionName" value="@Model.InstitutionName" required>
                    <span asp-validation-for="InstitutionName" class="text-danger"></span>
                </div>

                <div id="balanceField" class="form-group">
                    <label for="balance">Balance:</label>
                    <small class="form-text text-muted">Enter a positive or negative amount (e.g. 10 or -20)</small>
                    <input class="form-control" type="text" name="Balance" value="@Model.Balance.ToString("0.00")">
                    <span asp-validation-for="Balance" class="text-danger"></span>
                </div>
                <br />
                <div id="submitField" class="form-group">
                    <button type="submit" class="btn btn-primary" name="button" value="Submit">Submit</button>
                    <a href="/Account/Index" class="btn btn-secondary">Cancel</a>

                </div>

                <div id="validateField" class="form-group">
                    <button type="submit" class="btn btn-primary" name="button" value="Validate" onclick="setFormAction()">
                        Save and Proceed
                    </button>
                </div>
                <input type="hidden" name="UserID" value="@Model.UserID">
                <input type="hidden" name="BalanceForDay" value="" />
            </form>
        </div>
    </div>
</div>

<script>function setFormAction() {
        var accountNumber = document.getElementById("AccountNumberHidden").value;
        var form = document.querySelector("form");
        form.action = "/Account/AgreeRetrieveData?accountNumber=" + encodeURIComponent(accountNumber);
    }</script>


@*<script>$(document).ready(function () {
        $("#AccountForm").submit(function () {
            $("#createAccountBtn").prop("disabled", true);
        });
    });</script>*@